package j20251017;

public class Demo4 {
    public static void main(String[] args) {
        Object lock=new Object();
        Thread t1=new Thread(()->{
            synchronized (lock) {
                    System.out.println("等待前");
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("等待后");
            }
        });
        Thread t2=new Thread(()->{
            synchronized (lock) {
                System.out.println("通知前");
                lock.notify();
                System.out.println("通知后");
            }
        });
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
